# {{ cephadm_managed }}
global:
  scrape_interval: 10s
  evaluation_interval: 10s
  external_labels:
    cluster: {{ cluster_fsid }}

rule_files:
  - /etc/prometheus/alerting/*

{% if alertmanager_sd_url %}
alerting:
  alertmanagers:
{% if security_enabled %}
    - scheme: https
      basic_auth:
        username: {{ alertmanager_web_user }}
        password: {{ alertmanager_web_password }}
      tls_config:
        ca_file: root_cert.pem
        cert_file: prometheus.crt
        key_file:  prometheus.key
      path_prefix: '{{ alertmanager_url_prefix }}'
      http_sd_configs:
        - url: {{ alertmanager_sd_url }}
          basic_auth:
            username: {{ service_discovery_username }}
            password: {{ service_discovery_password }}
          tls_config:
            ca_file: root_cert.pem
{% else %}
    - scheme: http
      http_sd_configs:
        - url: {{ alertmanager_sd_url }}
{% endif %}
{% endif %}

scrape_configs:
  - job_name: 'ceph'
    relabel_configs:
    - source_labels: [__address__]
      target_label: cluster
      replacement: {{ cluster_fsid }}
    - source_labels: [instance]
      target_label: instance
      replacement: 'ceph_cluster'
{% if security_enabled %}
    scheme: https
    tls_config:
      ca_file: root_cert.pem
    honor_labels: true
    http_sd_configs:
    - url: {{ mgr_prometheus_sd_url }}
      basic_auth:
        username: {{ service_discovery_username }}
        password: {{ service_discovery_password }}
      tls_config:
        ca_file: root_cert.pem
{% else %}
    honor_labels: true
    http_sd_configs:
    - url: {{ mgr_prometheus_sd_url }}
{% endif %}

{% if node_exporter_sd_url %}
  - job_name: 'node'
    relabel_configs:
    - source_labels: [__address__]
      target_label: cluster
      replacement: {{ cluster_fsid }}
{% if security_enabled %}
    scheme: https
    tls_config:
      ca_file: root_cert.pem
      cert_file: prometheus.crt
      key_file:  prometheus.key
    http_sd_configs:
    - url: {{ node_exporter_sd_url }}
      basic_auth:
        username: {{ service_discovery_username }}
        password: {{ service_discovery_password }}
      tls_config:
        ca_file: root_cert.pem
{% else %}
    http_sd_configs:
    - url: {{ node_exporter_sd_url }}
{% endif %}
{% endif %}

{% if haproxy_sd_url %}
  - job_name: 'haproxy'
    relabel_configs:
    - source_labels: [__address__]
      target_label: cluster
      replacement: {{ cluster_fsid }}
{% if security_enabled %}
    scheme: https
    tls_config:
      ca_file: root_cert.pem
    http_sd_configs:
    - url: {{ haproxy_sd_url }}
      basic_auth:
        username: {{ service_discovery_username }}
        password: {{ service_discovery_password }}
      tls_config:
        ca_file: root_cert.pem
{% else %}
    http_sd_configs:
    - url: {{ haproxy_sd_url }}
{% endif %}
{% endif %}

{% if ceph_exporter_sd_url %}
  - job_name: 'ceph-exporter'
    relabel_configs:
    - source_labels: [__address__]
      target_label: cluster
      replacement: {{ cluster_fsid }}
{% if security_enabled %}
    honor_labels: true
    scheme: https
    tls_config:
      ca_file: root_cert.pem
    http_sd_configs:
    - url: {{ ceph_exporter_sd_url }}
      basic_auth:
        username: {{ service_discovery_username }}
        password: {{ service_discovery_password }}
      tls_config:
        ca_file: root_cert.pem
{% else %}
    honor_labels: true
    http_sd_configs:
    - url: {{ ceph_exporter_sd_url }}
{% endif %}
{% endif %}

{% if nvmeof_sd_url %}
  - job_name: 'nvmeof'
{% if security_enabled %}
    honor_labels: true
    scheme: https
    tls_config:
      ca_file: root_cert.pem
    http_sd_configs:
    - url: {{ nvmeof_sd_url }}
      basic_auth:
        username: {{ service_discovery_username }}
        password: {{ service_discovery_password }}
      tls_config:
        ca_file: root_cert.pem
{% else %}
    http_sd_configs:
    - url: {{ nvmeof_sd_url }}
{% endif %}
{% endif %}

{% if nfs_sd_url %}
  - job_name: 'nfs'
{% if security_enabled %}
    honor_labels: true
    scheme: https
    tls_config:
      ca_file: root_cert.pem
    http_sd_configs:
    - url: {{ nfs_sd_url }}
      basic_auth:
        username: {{ service_discovery_username }}
        password: {{ service_discovery_password }}
      tls_config:
        ca_file: root_cert.pem
{% else %}
    http_sd_configs:
    - url: {{ nfs_sd_url }}
{% endif %}
{% endif %}

{% if smb_sd_url %}
  - job_name: 'smb'
{% if security_enabled %}
    honor_labels: true
    scheme: https
    tls_config:
      ca_file: root_cert.pem
    http_sd_configs:
    - url: {{ smb_sd_url }}
      basic_auth:
        username: {{ service_discovery_username }}
        password: {{ service_discovery_password }}
      tls_config:
        ca_file: root_cert.pem
{% else %}
    http_sd_configs:
    - url: {{ smb_sd_url }}
{% endif %}
{% endif %}

{% for url, details in clusters_credentials.items() %}
  - job_name: 'federate_{{ loop.index }}'
    scrape_interval: 15s
    honor_labels: true
    metrics_path: {{ federate_path }}
    relabel_configs:
    - source_labels: [__address__]
      target_label: cluster
      replacement: {{ cluster_fsid }}
{% if security_enabled %}
    scheme: https
    tls_config:
      ca_file: {{ details['cert_file_name'] }}
    basic_auth:
      username: {{ details['user'] }}
      password: {{ details['password'] }}
{% endif %}
    params:
      'match[]':
        - '{job="ceph"}'
        - '{job="node"}'
        - '{job="haproxy"}'
        - '{job="ceph-exporter"}'
    static_configs:
    - targets: ['{{ url }}']
{% endfor %}

